package com.yyfax.common.form.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yyfax.common.CLog;
import com.yyfax.common.R;

import java.util.Arrays;
import java.util.List;


public class SearchTypeAdapter extends BaseAdapter<String> {
	private final int mColor2b92ec;
	private final int mColor333333;
	public List<String> mTypes = Arrays.asList("客户姓名", "身份证号", "借据号", "管户人", "还款日");
	private DetailItemClickListener mClickListener;
	private String mSelectedType = mTypes.get(0);

	public SearchTypeAdapter(Context context, DetailItemClickListener mClickListener) {
		super();
		this.mClickListener = mClickListener;
		 mColor2b92ec = context.getResources().getColor(R.color.color_2b92ec);
		 mColor333333 = context.getResources().getColor(R.color.color_333333);

	}
	@Override
	public int getCount() {
		return mTypes.size();
	}

	@Override
	public String getItem(int i) {
		return mTypes.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(final int i, View convertView, ViewGroup viewGroup) {
		final ViewHolder viewHolder;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) viewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.select_type_item_layout, viewGroup, false);;
			viewHolder = new ViewHolder(convertView);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if (mSelectedType.equals(mTypes.get(i))) {
			viewHolder.type.setTextColor(mColor2b92ec);
		} else {
			viewHolder.type.setTextColor(mColor333333);
		}
		viewHolder.type.setText(mTypes.get(i));
		viewHolder.type.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				if (null != mClickListener) {
					CLog.e("onCLick", "PopupWindow");
					mClickListener.onItemClick(i, mTypes.get(i));
				}
			}
		});
		return convertView;
	}

	static class ViewHolder {
		TextView type;

		ViewHolder(View view) {
			type= (TextView) view.findViewById(R.id.type_select_tv);
		}
	}

	public void setSelectedType(String type) {
		mSelectedType = type;
	}

	public String getSelectedType() {
		return mSelectedType;
	}

	public List<String> getTypes() {
		return mTypes;
	}

	public void setTypes(List<String> types) {
		mTypes=types;
		mSelectedType=types.get(0);
	}

	public interface DetailItemClickListener {
		void onItemClick(int position,String selectStatus);//点击进行选择状态
	}

}
